﻿using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using APP.HELPER.Data.Helper;
using APP.HELPER.Utils.CustomizeToolbox;
using DevExpress.XtraEditors;
using Microsoft.VisualBasic;
using ComboBox = System.Windows.Forms.ComboBox;

namespace Dictionary.ERP
{
    public class DIC_SALARY_STEP
    {
        private double m_Coefficient;
        private string m_Description;
        private string m_RankCode;
        private int m_StepCode;
        private string m_StepName;

        public DIC_SALARY_STEP()
        {
            m_StepCode = 0;
            m_RankCode = "";
            m_StepName = "";
            m_Coefficient = 0.0;
            m_Description = "";
        }

        public DIC_SALARY_STEP(int StepCode, string RankCode, string StepName, double Coefficient, string Description)
        {
            m_StepCode = StepCode;
            m_RankCode = RankCode;
            m_StepName = StepName;
            m_Coefficient = Coefficient;
            m_Description = Description;
        }

        [Category("Column"), DisplayName("Coefficient")]
        public double Coefficient
        {
            get { return m_Coefficient; }
            set { m_Coefficient = value; }
        }

        [DisplayName("Description"), Category("Column")]
        public string Description
        {
            get { return m_Description; }
            set { m_Description = value; }
        }

        public string ProductName
        {
            get { return "Class DIC_SALARY_STEP"; }
        }

        public string ProductVersion
        {
            get { return "1.0.0.0"; }
        }

        [DisplayName("RankCode"), Category("Column")]
        public string RankCode
        {
            get { return m_RankCode; }
            set { m_RankCode = value; }
        }

        [Category("Primary Key"), DisplayName("StepCode")]
        public int StepCode
        {
            get { return m_StepCode; }
            set { m_StepCode = value; }
        }

        [DisplayName("StepName"), Category("Column")]
        public string StepName
        {
            get { return m_StepName; }
            set { m_StepName = value; }
        }

        public void AddCombo(ComboBox combo)
        {
            GridCalendarControlLib.TableToComboBox(combo, GetList(), "StepName", "StepCode");
        }

        public void AddComboAll(ComboBox combo)
        {
            var list = new DataTable();
            list = GetList();
            DataRow row = list.NewRow();
            row["StepCode"] = "All";
            row["StepName"] = "Tất cả";
            list.Rows.InsertAt(row, 0);
            GridCalendarControlLib.TableToComboBox(combo, list, "StepName", "StepCode");
        }

        public void AddComboEdit(ComboBoxEdit combo)
        {
            var list = new DataTable();
            list = GetList();
            foreach (DataRow row in list.Rows)
            {
                combo.Properties.Items.Add(row["StepName"]);
            }
        }

        public void AddComboEditByRank(ComboBoxEdit combo, string RankCode)
        {
            combo.Properties.Items.Clear();
            var listByRank = new DataTable();
            listByRank = GetListByRank(RankCode);
            foreach (DataRow row in listByRank.Rows)
            {
                combo.Properties.Items.Add(row["StepCode"]);
            }
        }

        public string Delete()
        {
            string[] myParams = {"@StepCode"};
            object[] myValues = {m_StepCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_SALARY_STEP_Delete", myParams, myValues);
        }

        public string Delete(string StepCode)
        {
            string[] myParams = {"@StepCode"};
            object[] myValues = {StepCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_SALARY_STEP_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, string StepCode)
        {
            string[] myParams = {"@StepCode"};
            object[] myValues = {StepCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "DIC_SALARY_STEP_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string StepCode)
        {
            string[] myParams = {"@StepCode"};
            object[] myValues = {StepCode};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DIC_SALARY_STEP_Delete", myParams, myValues);
        }

        public bool Exist(string StepCode, string RankCode)
        {
            bool hasRows = false;
            string[] myParams = {"@StepCode", "@RankCode"};
            object[] myValues = {StepCode, RankCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("DIC_SALARY_STEP_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public string Get(string StepCode, string RankCode)
        {
            string str = "";
            string[] myParams = {"@StepCode", "@RankCode"};
            object[] myValues = {StepCode, RankCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("DIC_SALARY_STEP_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_StepCode = Convert.ToInt32(reader["StepCode"]);
                    m_RankCode = Convert.ToString(reader["RankCode"]);
                    m_StepName = Convert.ToString(reader["StepName"]);
                    m_Coefficient = Convert.ToDouble(reader["Coefficient"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, string StepCode, string RankCode)
        {
            string str = "";
            string[] myParams = {"@StepCode", "@RankCode"};
            object[] myValues = {StepCode, RankCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "DIC_SALARY_STEP_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_StepCode = Convert.ToInt32(reader["StepCode"]);
                    m_RankCode = Convert.ToString(reader["RankCode"]);
                    m_StepName = Convert.ToString(reader["StepName"]);
                    m_Coefficient = Convert.ToDouble(reader["Coefficient"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, string StepCode, string RankCode)
        {
            string str = "";
            string[] myParams = {"@StepCode", "@RankCode"};
            object[] myValues = {StepCode, RankCode};
            var helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "DIC_SALARY_STEP_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    m_StepCode = Convert.ToInt32(reader["StepCode"]);
                    m_RankCode = Convert.ToString(reader["RankCode"]);
                    m_StepName = Convert.ToString(reader["StepName"]);
                    m_Coefficient = Convert.ToDouble(reader["Coefficient"]);
                    m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public DataTable GetList()
        {
            var helper = new SqlHelper();
            return helper.ExecuteDataTable("DIC_SALARY_STEP_GetList");
        }

        public DataTable GetListByRank(string RankCode)
        {
            string[] myParams = {"@RankCode"};
            object[] myValues = {RankCode};
            var helper = new SqlHelper();
            return helper.ExecuteDataTable("DIC_SALARY_STEP_GetListByRank", myParams, myValues);
        }

        public string Insert()
        {
            string[] myParams = {"@StepCode", "@RankCode", "@StepName", "@Coefficient", "@Description"};
            object[] myValues = {m_StepCode, m_RankCode, m_StepName, m_Coefficient, m_Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_SALARY_STEP_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = {"@StepCode", "@RankCode", "@StepName", "@Coefficient", "@Description"};
            object[] myValues = {m_StepCode, m_RankCode, m_StepName, m_Coefficient, m_Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DIC_SALARY_STEP_Insert", myParams, myValues);
        }

        public string Insert(string StepCode, string StepName, string Description)
        {
            string[] myParams = {"@StepCode", "@RankCode", "@StepName", "@Coefficient", "@Description"};
            object[] myValues = {StepCode, RankCode, StepName, Coefficient, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_SALARY_STEP_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, string StepCode, string StepName, string Description)
        {
            string[] myParams = {"@StepCode", "@RankCode", "@StepName", "@Coefficient", "@Description"};
            object[] myValues = {StepCode, RankCode, StepName, Coefficient, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "DIC_SALARY_STEP_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, string StepCode, string StepName, string Description)
        {
            string[] myParams = {"@StepCode", "@RankCode", "@StepName", "@Coefficient", "@Description"};
            object[] myValues = {StepCode, RankCode, StepName, Coefficient, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DIC_SALARY_STEP_Insert", myParams, myValues);
        }

        public string NewID()
        {
            return NewID("DIC_SALARY_STEP", "StepCode", "RankCode", m_RankCode);
        }

        public string NewID(string RankCode)
        {
            return NewID("DIC_SALARY_STEP", "StepCode", "RankCode", RankCode);
        }

        public string NewID(string tableName, string primaryColumn, string foreignColumn, string fKey)
        {
            var helper = new SqlHelper
            {
                CommandType = CommandType.Text
            };
            string expression = "";
            object obj2 =
                helper.ExecuteScalar("select max([" + primaryColumn + "]) from [" + tableName + "] where [" +
                                     foreignColumn + "] = N'" + fKey + "'");
            expression = (obj2 == null) ? "0" : obj2.ToString();
            if (fKey.Length != 0)
            {
                expression = expression.Replace(fKey, "").Trim();
            }
            int num = 0;
            if (SqlHelper.IsNumeric(expression))
            {
                num = (int) Conversion.Val(expression);
            }
            num++;
            string str2 = num.ToString();
            while (str2.Length < 6)
            {
                str2 = "0" + str2;
            }
            return str2;
        }

        public string Update()
        {
            string[] myParams = {"@StepCode", "@RankCode", "@StepName", "@Coefficient", "@Description"};
            object[] myValues = {m_StepCode, m_RankCode, m_StepName, m_Coefficient, m_Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_SALARY_STEP_Update", myParams, myValues);
        }

        public string Update(string StepCode, string StepName, string Description)
        {
            string[] myParams = {"@StepCode", "@RankCode", "@StepName", "@Coefficient", "@Description"};
            object[] myValues = {StepCode, RankCode, StepName, Coefficient, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery("DIC_SALARY_STEP_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, string StepCode, string StepName, string Description)
        {
            string[] myParams = {"@StepCode", "@RankCode", "@StepName", "@Coefficient", "@Description"};
            object[] myValues = {StepCode, RankCode, StepName, Coefficient, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "DIC_SALARY_STEP_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, string StepCode, string StepName, string Description)
        {
            string[] myParams = {"@StepCode", "@RankCode", "@StepName", "@Coefficient", "@Description"};
            object[] myValues = {StepCode, RankCode, StepName, Coefficient, Description};
            var helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "DIC_SALARY_STEP_Update", myParams, myValues);
        }
    }
}